define(['jquery', 'bootstrap', 'backend', 'table', 'form'], function ($, undefined, Backend, Table, Form) {


    var Controller = {
        index: function () {
            var window_innerheight = window.innerHeight;
            var table_height = window_innerheight-20;
            // 初始化表格参数配置
            Table.api.init({
                extend: {
                    index_url: 'user/user/index',
                    add_url: 'user/user/add',
                    edit_url: 'user/user/edit',
                    del_url: 'user/user/del',
                    multi_url: 'user/user/multi',
                    table: 'user',
                },

                pageSize: Config.pagesize,
                // height: table_height
            });

            var table = $("#table");

            // 初始化表格
            table.bootstrapTable({
                url: $.fn.bootstrapTable.defaults.extend.index_url,
                pk: 'id',
                sortName: 'user.id',
                columns: [
                    [
                        {checkbox: true},
                        {field: 'id', title: __('Id'),operate: false,visible: false},
                        {field: 'group.name', title: __('Group'),operate: false},

                        {field: 'username', title: "昵称", operate: 'LIKE'},
                        {field: 'mobile', title: __('Mobile'), operate: 'LIKE'},
                        {field: 'avatar', title: __('Avatar'), events: Table.api.events.image, formatter: Table.api.formatter.image, operate: false},
                        {field: 'qrcode', title: "推广码", events: Table.api.events.image, formatter: Table.api.formatter.image, operate: false},




                        {field: 'tui_nums', title: "推广人数", operate: false},
                        {field: 'total_hours', title: "小时数", operate: false},
                        {field: 'successions', title: "连续登录", operate: false},

                        {field: 'loginfailure', title: __('fail num'), visible: false, operate: false},

                        {field: 'logintime_text', title: __('Logintime'),  operate: false},
                        {field: 'logintime', title: __('Logintime'),  operate: 'RANGE', addclass: 'datetimerange',visible: false},

                        {field: 'jointime_text', title: __('Jointime'),operate: false},
                        {field: 'jointime', title: __('Jointime'),  operate: 'RANGE', addclass: 'datetimerange',visible: false},

                         {field: 'status', title: __('Status'), formatter: Table.api.formatter.status, searchList: {normal: __('Normal'), hidden: __('Forbiden')}},
                        {field: 'operate', title: __('Operate'), table: table,
                            buttons: [

                            ],
                            events: Table.api.events.operate,
                            formatter: Table.api.formatter.operate}
                    ]
                ]
            });

            // 为表格绑定事件
            Table.api.bindevent(table);
        },
        add: function () {
            Controller.api.bindevent();
        },
        showtaocan: function () {
            Controller.api.bindevent();
        },
        kaika: function () {
            Controller.api.bindevent();
        },
        edit: function () {
            Controller.api.bindevent();
        },
        api: {
            bindevent: function () {
                Form.api.bindevent($("form[role=form]"));
            },
            formatter: {
                setUsertype: function (value, row, index) {
                    if(row.user_type == 0){
                        var html = __('Regular users');
                    }else if(row.user_type == 1){
                        var html = __('Admins');
                    }else{
                        var html = __('Teacher');
                    }
                    return html;
                },
            }
        }
    };
    return Controller;
});
